import request from '@/utils/request';

export async function queryRule(params, id) {
  const limit = params.pageSize;
  const page = params.current;
  const my_params = {
    limit: limit,
    page: page,
    goodsId: id,
  };
  Object.assign(params, my_params);
  return request('/goods/goodsItem/list', {
    params,
  });
}

export async function queryRecord(params, id) {
  const limit = params.pageSize;
  const page = params.current;
  const my_params = {
    limit: limit,
    page: page,
    goodsId: id,
  };
  Object.assign(params, my_params);
  return request('/goods/goodsItemStockRecord/page2', {
    params,
  });
}

export async function getRecordTotal(goodsItemStoreId) {
  const params = {
    goodsItemStoreId: goodsItemStoreId,
  };
  return request('/goods/goodsItemStockRecord/totle', {
    params,
  });
}

export async function removeRule(params) {
  return request(`goods/goodsItem/${params}`, {
    method: 'DELETE',
  });
}
export async function addRule(params) {
  return request('/goods/goodsItem', {
    method: 'POST',
    data: params,
  });
}
export async function updateRule(params) {
  return request('/goods/goodsItem', {
    method: 'PUT',
    data: params,
  });
}
export async function queryStore(params, id) {
  const limit = params.pageSize;
  const page = params.current;
  const my_params = {
    limit: limit,
    page: page,
    goodsId: id,
  };
  Object.assign(params, my_params);
  return request('/store/store/page', {
    params,
  });
}

export async function storeRelation(params) {
  return request('/store/goodsStore/batch', {
    method: 'POST',
    data: params,
  });
}
export async function getRelation(params) {
  return request('/store/goodsStore/list', {
    params,
  });
}
export async function updateRelation(params) {
  return request(`/store/goodsStore/batch?goodsItemId=${params[0].goodsItemId}`, {
    method: 'PUT',
    data: params,
  });
}

export async function removeRelation(params) {
  return request(`/store/goodsStore/${params}`, {
    method: 'DELETE',
  });
}
